import 'package:fish_redux/fish_redux.dart';
import 'package:flutter/material.dart';
import 'package:kunlun_gas/app_files.dart';
import 'package:webview_flutter/webview_flutter.dart';
import 'action.dart';
import 'state.dart';

Widget buildView(
    AlipayViewState state, Dispatch dispatch, ViewService viewService) {
  return Scaffold(
    backgroundColor: Color.fromRGBO(244, 245, 245, 1.0),
    appBar: myAppBar(viewService.context,title: '支付宝'),
    body: Stack(
      children: <Widget>[
        Offstage(
          offstage: !state.isLoaded,
          child:  SafeArea(
            child: SizedBox.expand(
              child: WebView(
                onWebViewCreated: (WebViewController controller) =>
                    dispatch(AlipayViewActionCreator.onWebViewCreate(controller)),
                onPageFinished: (_) =>
                    dispatch(AlipayViewActionCreator.onPageFinished()),
                javascriptMode: JavascriptMode.unrestricted,
                navigationDelegate: (NavigationRequest request) {
                  dispatch(AlipayViewActionCreator.onHandleUrl(request.url));
                  return NavigationDecision.navigate;
                },
              ),
            ),
          ),
        ),
        Offstage(
          offstage: state.isLoaded,
          child: SpinKitCircle(color: ThemeConfig.mainColor),
        )
      ],
    ),
  );
}
